﻿using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;

namespace WebsiteForWorkFlow.Data
{
    public class DataInstance
    {
        public static string Result = "1";

        static string _ShowMEssage = "";
        public static string ShowMessage
        {
            get { return _ShowMEssage; }
            set { _ShowMEssage = value; }
        }
        public static void AppendMessage(string message)
        {
            _ShowMEssage += message + "\r\n";
            _ShowMEssage += "=======================================================\r\n";
        }

        public static void AppendMessage(Dictionary<string, string> dict)
        {
            _ShowMEssage += SerializeJson(dict) + "\r\n";
            _ShowMEssage += "=======================================================\r\n";
        }

        public static string SerializeJson<T>(T obj, int indentation = 0, char indentchar = ' ')
        {
            StringWriter writer = new StringWriter();
            JsonTextWriter jsoonWriter = new JsonTextWriter(writer)
            {
                Formatting = Formatting.Indented,
                Indentation = indentation,
                IndentChar = indentchar
            };
            JsonSerializer serializer = new JsonSerializer();
            serializer.Serialize(jsoonWriter, obj);
            return writer.ToString();
        }
    }
}
